<template>
	<view class="wrap">
		<view class="head">
			<u-avatar :src="src" size=160></u-avatar>
		</view>
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType" >
			<u-form-item  label-width="120" :label-position="labelPosition"  prop="name" :border-bottom="false">
				<u-input :border="border" placeholder="请输入账号" v-model="model.name" type="text" ></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition"  prop="password" :border-bottom="false">
				<u-input :password-icon="true" :border="border" type="password" v-model="model.password" placeholder="请输入密码"></u-input>
			</u-form-item>
			<!-- <u-form-item :label-position="labelPosition"  label-width="150" prop="rePassword" :border-bottom="false">
				<u-input :border="border" type="password" v-model="model.rePassword" placeholder="请确认密码"></u-input>
			</u-form-item> -->
			<u-button  type="primary" @click="submit" style="margin-top: 30rpx;">登录</u-button>
			<view class="tool">
				<view class="reg">
					<text>新用户注册</text>
				</view>
				<view class="forget">
					<text>忘记密码</text>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					intro: ''
				},
				labelPosition: 'left',
				border: true,
				rules: {
					intro: [
						{
							required: true,
							message: '请填写简介'
						},
						{
							min: 5,
							message: '简介不能少于5个字',
							trigger: 'change' ,
						},
						// 正则校验示例，此处用正则校验是否中文，此处仅为示例，因为uView有this.$u.test.chinese可以判断是否中文
						{
							pattern: /^[\u4e00-\u9fa5]+$/gi,
							message: '简介只能为中文',
							trigger: 'change',
						},
					]
				},
				errorType: ['message']
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				console.log('提交')
			},
			errorChange(index) {
				if(index == 0) this.errorType = ['message'];
				if(index == 1) this.errorType = ['toast'];
				if(index == 2) this.errorType = ['border-bottom'];
				if(index == 3) this.errorType = ['border'];
			}
		}
	}
</script>

<style>
	.wrap {
		padding: 60rpx;
	}
	.head{
		width: 90%;
		margin: auto;
		text-align: center;
		margin-top: 100rpx;
		margin-bottom: 40rpx;
	}
	.tool{
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;
	}
	.tool view{
		color: #007AFF;
	}
</style>
